package com.sinoglobal.sinostore.adapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.sinoglobal.sinostore.R;
import com.sinoglobal.sinostore.bean.GoodsTypeListVo.GoodsTypeVo;
/***
 * 
* @title: ShippingMethodAdapter.java 
* @package com.chiliring.sinostore.adapter 
* @description: TODO(发票信息 商品类型 adapter) 
* @author LK
* @date 2015-1-16 上午10:39:50
 */
public class InvoiceGoodsTypeAdapter extends BaseAdapter {
	private Context context;
	
	private List<GoodsTypeVo> data;
	
	private Map<Integer,Boolean> selects = new HashMap<Integer,Boolean>();
	
	public InvoiceGoodsTypeAdapter(Context context,List<GoodsTypeVo> data){
		this.context = context;
		this.data = data;
		for(int i= 0;i<data.size();i++){
			selects.put(i, false);
		}
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	
	@Override
	 public View getView(final int position, View convertView, ViewGroup parent) {  
		if(null == convertView){
			convertView = LayoutInflater.from(context).inflate(R.layout.shop_item_shipping_method, null);
		}
         CheckBox checkBox = ViewHolder.getViewById(convertView, R.id.cb_choose);
         TextView tvShippingName = ViewHolder.getViewById(convertView, R.id.tv_shipping_name);
         tvShippingName.setText(String.format("%s", data.get(position).name));
         checkBox.setChecked(selects.get(position));  
         return convertView;  
     }  

	public void setSelect(int position){
		boolean cu = true;
        if(!selects.get(position)){
        	cu = true;
        }
        // 先将所有的置为FALSE  
        for(Integer p : selects.keySet()) {  
       	 selects.put(p, false);  
        }  
        // 再将当前选择CB的实际状态  
        selects.put(position, cu);  
        notifyDataSetChanged();
	}
}
